using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using ImPM.Data.ManagerObjects;
using ImPM.Data.BusinessObjects;
using ImPM.Data.Base;

namespace ImPM.Data.UnitTests
{
	[TestFixture]
    public partial class ProjectTests : UNuitTestBase
    {
        protected IProjectManager manager;
		
		public ProjectTests()
        {
            manager = managerFactory.GetProjectManager();
        }
		
		protected Project CreateNewProject()
		{
			Project entity = new Project();
			
			
			entity.ProjectName = "Test Test ";
			entity.StartDate = DateTime.Now;
			entity.FinishDate = DateTime.Now;
			entity.ProjectGUID = "Test Test Test";
			entity.ProjectOwner = 7;
			
			return entity;
		}
		protected Project GetFirstProject()
        {
            IList<Project> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				Project entity = CreateNewProject();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                Project entityA = CreateNewProject();
				manager.Save(entityA);

                Project entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                Project entityA = GetFirstProject();
				entityA.ProjectName = "Test Test ";
				
				manager.Update(entityA);

                Project entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.ProjectName, entityB.ProjectName);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                Project entity = GetFirstProject();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}